package com.wuyunonline.tracelog.aop;

import com.wuyunonline.tracelog.common.constant.TraceLogConstant;
import com.wuyunonline.tracelog.common.util.TraceIdUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

/**
 * 给@Scheduled,@PostConstruct创建traceId切面
 * @author wuyun
 */
@Aspect
@Component
public class TracelogAspect {

    @Pointcut("@annotation(org.springframework.scheduling.annotation.Scheduled) || @annotation(javax.annotation.PostConstruct)")
    public void tracelogPointCut() {
    }

    @Around("tracelogPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        MDC.put(TraceLogConstant.TRACE_ID, TraceIdUtil.uuid_timestamp());
        return point.proceed();
    }

}
